﻿@model FFLTask.SRV.ViewModel.Task.EditModel
@using FFLTask.GLB.Global.Enum
@using Global.Core.Helper
@using Global.Core.ExtensionMethod
@Html.Partial("EditColumns/_Edit_Subtitle", TaskProcess.Publish, new ViewDataDictionary { { "Edit", true } })
<table id="@TaskProcess.Publish">
    <tr>
        <th class="first_column">
            项目：
        </th>
        <td colspan="3">
            @Html.EditorFor(m => m.CurrentProject, "Project/_DropDownListLinkedProject")
        </td>
    </tr>
    <tr>
        <th>
            父任务：
        </th>
        <td colspan="3">
            @Html.TextBoxFor(m => m.TaskItem.Parent.Id)
            <label>@Html.RadioButtonFor(m => m.IdOrName, SearchBy.Name) @SearchBy.Name.GetEnumDescription()</label>
            <label>@Html.RadioButtonFor(m => m.IdOrName, SearchBy.Id) @SearchBy.Id.GetEnumDescription() </label>
            <a href="#" id="find">查找</a>
            <br />
            @Html.ValidationMessageFor(m => m.TaskItem.Parent.Id, "* 编号只能为数字")
            <div id="parentList"></div>
            @if (ViewBag.ParentIsOwnOffspring != null && (bool)ViewBag.ParentIsOwnOffspring)
            {
                <span class="field-validation-error">* 该父任务是当前任务的子任务</span>
            }
            @if (ViewBag.ShowNotFound != null && (bool)ViewBag.ShowNotFound)
            {
                <span class="field-validation-error" id="not_find">* 无法找到该编号的任务</span>
            }
            else
            {
                <span class="field-validation-error" id="not_find" style="display: none">* 无法找到该编号的任务</span>
            }
            @if (Model.TaskItem.Parent != null)
            {
                @Html.ActionLink(Model.TaskItem.Parent.Title, "Edit", new { taskId = Model.TaskItem.Parent.Id }, new { id = "parent_title" })
                <span>[@Html.ActionLink("关系", "Relation", new { taskId = Model.TaskItem.LiteItem.Id }, new { name = "relation" })]</span>
            }
        </td>
    </tr>
    <tr>
        <th class="first_column">
            标题：
        </th>
        <td colspan="3">
            @Html.Partial("_Node_Type", Model.TaskItem.LiteItem)
            @Html.TextBoxFor(m => m.TaskItem.LiteItem.Title, new { style = " width: 406px;" })
            [@Html.ActionLink("关系", "Relation", new { taskId = Model.TaskItem.LiteItem.Id }, new { name = "relation", style = "font-size: 12px;" })]
            <br />
            @Html.ValidationMessageFor(m => m.TaskItem.LiteItem.Title)
        </td>
    </tr>
    <tr>
        <th class="top_align first_column">
            内容：
        </th>
        <td class="textarea" colspan="3">
            @Html.TextAreaFor(m => m.TaskItem.Body, new { style = "width:480px; height:100px;" })
        </td>
    </tr>
    @Html.Partial("_Attachments")
    <tr>
        <th class="first_column">
            难度：
        </th>
        <td class="second_column">
            @Html.DropDownListFor(m => m.TaskItem.Difficulty, Model.AllDifficulties.GetSelectListItems<TaskDifficulty>(), "----")
        </td>
        <th class="third_column">
            工时(分钟)：
        </th>
        <td class="fourth_column">
            @Html.TextBoxFor(m => m.TaskItem.ExpectedWorkPeriod)
        </td>
    </tr>
    <tr>
        <th>
            优先级：
        </th>
        <td>
            @Html.DropDownListFor(m => m.TaskItem.Priority, Model.AllPriorities.GetSelectListItems<TaskPriority>(), "---")
        </td>
        <th>
            预计完成时间：
        </th>
        <td>
            @Html.EditorFor(m => m.ExpectedComplete)
        </td>
    </tr>
    <tr>
        <th>
            验收人：
        </th>
        <td>
            @Html.DropDownListFor(m => m.TaskItem.Accepter.Id, new SelectList(Model.Accepters, "Id", "Name"), "-----")
        </td>
        <th>
            虚任务：
        </th>
        <td>
            @Html.CheckBoxFor(m => m.TaskItem.LiteItem.Virtual)
            @Html.ValidationMessageFor(m => m.TaskItem.LiteItem.Virtual)
        </td>
</table>
<script type="text/javascript">
    var idOrName = "@Html.IdFor(m=>m.IdOrName)";

    var editorBody;
    $(document).ready(function () {
        KindEditor.ready(function (K) {
            editorBody = K.create('textarea[name="TaskItem.Body"]', {
                allowFileManager: false,
                @Html.Partial("KindEditorItems/_Simple")
            });
            editorBody.readonly(true);
        });

        $("#find").hide();
        $("#@Html.IdFor(x => x.TaskItem.Parent.Id)").focus(function () {
            onParentFocus($(this));
        });

        $("#find").click(function (event) {
            var taskId = $("#@Html.IdFor(x => x.TaskItem.Parent.Id)").val();
            var byName = $("#" + idOrName + ":checked").val() == "Name";
            findParentTask(event, taskId, byName);
        });

        $("#@Html.IdFor(m => m.TaskItem.LiteItem.Virtual)").click(function () {
            markTaskIsVirtual($(this));
        });
    });

    function refreshProject(event) {
        var projectId = get_current_project_id($(event));
        canPublish(projectId);
        refreshOwner(projectId, "#@Html.IdFor(x => x.TaskItem.Owner.Id)");
        refreshDifficulties(projectId, "#@Html.IdFor(x => x.TaskItem.Difficulty)");
        refreshPriority(projectId, "#@Html.IdFor(x => x.TaskItem.Priority)");
        refreshAccepter(projectId, "#@Html.IdFor(x => x.TaskItem.Accepter.Id)");
    }
</script>
